home *** CD-ROM | disk | FTP | other *** search
/ FM Towns: Free Software Collection 4 / FM Towns Free Software Collection 4 - Disc 1.iso / t_os / border / source / dabe_mos.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-10-19  |  7.3 KB  |  312 lines

  1. #include     <egb.h>
  2. #include    <mos.h>
  3. #include    <fmc.h>
  4. #include    <string.h>
  5. #include    "dabe.h"
  6.  
  7. #define    DWORD(x)    *((unsigned int            *)(x))
  8. #define    WORD(x)        *((unsigned short int    *)(x))
  9.  
  10. extern    char    work[];
  11. extern    char    swork[];
  12. extern    char    mwork[];
  13. extern    char    para[];
  14. extern    int        ox, oy;
  15. extern    int        event1_x, event1_y;
  16. extern    int        event2_x, event2_y;
  17. extern    int        event3_x, event3_y;
  18. extern    int        botton_x, botton_y[];    
  19. extern    short    rad;
  20.  
  21. char    mp[ (32 + 7) / 8 * 4 * 32 ];
  22.  
  23.  
  24. short    MOS_read( float lox, float loy, short komsu, char *msg, short arraylen, short page, short putflag )
  25. {
  26.     /************************************************************************/
  27.     /* i  lox == MOUSEの移動範囲の上端の開始x座標(16ドット単位)   */
  28.     /* i  loy == MOUSEの移動範囲の上端の開始y座標(16ドット単位)   */
  29.     /* i  komsu == 選択項目の数                                                */
  30.     /* c  *msg == メッセージ配列の先頭アドレス                                */
  31.     /* i  arraylen == メッセージの長さ                                        */    
  32.     /*                                                                        */
  33.     /*                                                                        */
  34.     /* メッセージ配列の先頭にタイトル名を入れ、その後に選択項目名を入れる。  */
  35.     /* メッセージ配列は、配列名〔項目数〕〔xlen〕の形式をとること。        */
  36.     /* その後、この関数を呼び出すこと。                                        */
  37.     /* 返り値 == 選択項目の番号(komnum)                            */
  38.     /************************************************************************/
  39.  
  40.     int        ch, x, y;
  41.     short    i;
  42.     static    int        mr_ox, mr_oy;
  43.     static    int        save_mr_ox, save_mr_oy;
  44.     static    short    border[40]; /* 選択項目BOXの境界y座標 */
  45.     static    short    linenum; /* 選択項目の番号 */
  46.     short    sound;
  47.     
  48.     /* 画面設定 */
  49.     EGB_writePage( work, page );
  50.     EGB_paintMode( work, 0x22);
  51.     
  52.     if( (putflag == NEW) || (putflag == SAVE) ){    
  53.          
  54.          linenum = 1;
  55.          
  56.          /* 境界の設定 */
  57.         for( i = 0; i <= komsu; i++ )
  58.             border[i] = ( (loy + i) * 16 ) + 1;
  59.         
  60.         /* Titleを表示 */
  61.         if( arraylen != 70 )
  62.             sound = SOUND_ON;
  63.         else
  64.             sound = SOUND_OFF;
  65.         strcpy(swork, msg);
  66.         g_wintitle( lox, (lox + arraylen / 2), (loy - 1),  TITCOL, UTICOL, DTICOL, TCHCOL, swork, page, sound );
  67.         
  68.         strcpy(swork, msg + arraylen);
  69.         g_winkom( lox, (lox + arraylen / 2), loy, RKOCOL, UKOCOL, DKOCOL, CHRCOL, swork, page );
  70.         for( i = 2; i <= komsu; i++ ){
  71.             strcpy( swork, msg + (i * arraylen) );
  72.             g_winkom( lox, (lox + arraylen / 2), loy + i - 1,  KOMCOL, UKOCOL, DKOCOL, CHRCOL, swork, page ); 
  73.         }
  74.     }
  75.     
  76.     /* MOUSE移動範囲等の設定  */
  77.        cmwork( mwork ); 
  78.     MOS_start( mwork, 4096 );
  79.     MOS_horizon( (lox * 16) + 1, ( (lox + arraylen / 2) * 16) - 1);
  80.     MOS_vertical( (loy * 16) + 1, ( (loy + komsu) * 16) - 1);
  81.     if( (putflag == NEW) || (putflag == SAVE) )    
  82.         MOS_setpos( mr_ox = (lox * 16) + 1, mr_oy = (loy * 16) + 1);
  83.     else
  84.         MOS_setpos( mr_ox = save_mr_ox , mr_oy = save_mr_oy );
  85.     
  86.     getcurbak( mr_ox, mr_oy );
  87.     putcur( mr_ox, mr_oy );
  88.         
  89.     
  90.     /* MOUSE読み取りスタート*/
  91.     do
  92.     {
  93.         MOS_rdpos(&ch, &x, &y);
  94.         
  95.         if ( (y < border[linenum - 1]) || (y > border[linenum]) )
  96.         {
  97.             putcurbak( mr_ox, mr_oy );
  98.             
  99.             strcpy( swork, msg + (linenum * arraylen) );
  100.             g_winkom( lox, (lox + arraylen / 2), (linenum + loy - 1),  KOMCOL, UKOCOL, DKOCOL, CHRCOL, swork, page );
  101.             if ( y < border[linenum - 1] )
  102.             {
  103.                 while( (y <= border[linenum - 1]) && (linenum > 1) )
  104.                     linenum--;
  105.             }
  106.             else
  107.             {
  108.             
  109.                 while( (y >= border[linenum]) && (linenum < komsu) )
  110.                     linenum++;
  111.             }
  112.             
  113.             strcpy( swork, msg + (linenum * arraylen) );
  114.             g_winkom( lox, ( lox + arraylen / 2 ),( linenum + loy - 1), RKOCOL, UKOCOL, DKOCOL, CHRCOL, swork, page );
  115.             
  116.             getcurbak( x, y );
  117.             putcur( x, y );
  118.                
  119.         }else{    
  120.             if( (x != mr_ox) || (y != mr_oy) ){    
  121.                 putcurbak( mr_ox, mr_oy );
  122.                 getcurbak( x, y );
  123.                 putcur( x, y );
  124.             }
  125.         }    
  126.            
  127.            mr_ox = x;
  128.         mr_oy = y;
  129.         
  130.     }while( ch == 0 );
  131.     
  132.     putcurbak( mr_ox, mr_oy );
  133.         
  134.     if( putflag == SAVE || putflag == RESTART ){
  135.         save_mr_ox = mr_ox;
  136.         save_mr_oy = mr_oy;
  137.     }
  138.             
  139.     MOS_end();
  140.     
  141.     if( page == page1 ){
  142.         WORD( para + 0 ) = 0;
  143.         WORD( para + 2 ) = 0;
  144.         WORD( para + 4 ) = 639;
  145.         WORD( para + 6 ) = 479;
  146.         EGB_writePage( work, 0x01 );
  147.         EGB_color( work, 0, 0 );
  148.         EGB_color( work, 2, 0 );
  149.         EGB_rectangle( work, para ); 
  150.     }
  151.     
  152.     switch(ch){
  153.         case 1:    BPB_freeon2( 10, 2000 );
  154.                 return    linenum;
  155.         case 2: return  Rbotton;
  156.         case 3: return  Rbotton;
  157.     }
  158. }
  159.  
  160. void    mos_start()
  161. {
  162.        cmwork( mwork ); 
  163.     MOS_start( mwork, 4096 );
  164.     MOS_horizon( 0, 639 );
  165.     MOS_vertical( 0, 479 );
  166.     MOS_setpos( ox, oy );
  167.     getcurbak( ox, oy );
  168.     putcur( ox, oy );
  169. }
  170.  
  171. void    mos_end()
  172. {    
  173.     putcurbak( ox, oy );
  174.     MOS_end();
  175. }
  176.  
  177. short    mos_sub()
  178. {
  179.        int        ch, x, y;    
  180.        short    i;
  181.        
  182.        MOS_rdpos( &ch, &x, &y );
  183.     
  184.     if( ( x != ox ) || ( y != oy ) ){    
  185.         putcurbak( ox, oy );
  186.         getcurbak( x, y );
  187.         putcur( x, y );
  188.     }
  189.     ox = x;
  190.     oy = y;
  191.  
  192.     if( ch == 1 ){    
  193.         if( (x > event2_x) && (x < (event2_x + 31)) && (y > event2_y) && (y < (event2_y + 31)) ){         
  194.             BPB_freeon2( 10, 2500 );
  195.             return    2; 
  196.         }
  197.         if( (x > event3_x) && (x < (event3_x + 31)) && (y > event3_y) && (y < (event3_y + 31)) ){        
  198.             BPB_freeon2( 10, 3000 );
  199.             return    3; 
  200.         }
  201.         if( ( x > botton_x ) && ( x < botton_x + 16 ) ){
  202.             for( i = 1; i <= 12; i++ ){
  203.                 if( y > botton_y[ i - 1 ] && y < botton_y[ i - 1 ] + 16 )
  204.                     break;
  205.             }
  206.             if( i <= 12 )
  207.                 return    i + 10;
  208.         }
  209.     }
  210.     
  211.     if( ch == 2 )
  212.         return    -2;
  213.     
  214.     return    0;
  215.         
  216. }
  217.  
  218.  
  219.  
  220.  
  221. short        MOS_loop()
  222. {
  223.     int        ch, x, y;
  224.        
  225.        cmwork( mwork ); 
  226.     MOS_start( mwork, 4096 );
  227.     MOS_resolution( 0, 12 );
  228.     MOS_disp(0);
  229.     
  230.     do
  231.     {
  232.         MOS_rdpos( &ch, &x, &y );
  233.     }while( (ch != 1) && (ch != 2) && (ch != 3) );
  234.     
  235.     MOS_end();
  236.     
  237.     ch *= (-1);
  238.     return ch;
  239. }
  240.  
  241. short     MOS_YesNo()
  242. {    
  243.     short    x, y;
  244.     
  245.     char    mosmsg[3][10] = { "選択","Yes","No" };
  246.     short        ret;
  247.     
  248.     rad--;
  249.     get_xy( &x, &y );
  250.     
  251.     ret = MOS_read( x + 15, y + 4.5,  2, mosmsg[0], 10, page0, NEW );
  252.     return    ret;
  253.     
  254. }
  255.  
  256. void     cmwork( char *mwork )
  257. {
  258.     short        count;
  259.     
  260.     for( count = 0; count < 4096; count++ ){
  261.         *mwork = (char)0x00;
  262.         mwork++;
  263.     }    
  264. }
  265.  
  266. void    putcur( int x, int y )
  267. {
  268.     EGB_writePage( work, 0x01 );
  269.     
  270.     DWORD(para + 0) = 0x28000+0x56*256 ;
  271.     WORD(para + 4) = 0x108 ;
  272.     WORD(para + 6) = x;
  273.     WORD(para + 8) = y;
  274.     WORD(para + 10) = x + 31;
  275.     WORD(para + 12) = y + 31;
  276.     EGB_color( work, 0, 9 );
  277.     EGB_putBlockColor( work, 0 ,para ) ;
  278.     
  279.     WORD(para + 0) = x + 3;
  280.     WORD(para + 2) = y + 3 ;
  281.     WORD(para + 4) = 1;
  282.     WORD(para + 6) = 0;
  283.     DWORD(para + 8) = 9;
  284.     EGB_color( work, 2, 15 ) ;
  285.     EGB_paint( work, para ) ;
  286. }
  287.  
  288. void    getcurbak( int x, int y )
  289. {
  290.     EGB_writePage( work, 0x01 );
  291.     DWORD( mp + 0 ) = (unsigned int)( mp + 14 );
  292.     WORD( mp +  4 ) = 0x014;    
  293.     WORD( mp +  6 ) = x;
  294.     WORD( mp +  8 ) = y;
  295.     WORD( mp + 10 ) = x + 18;
  296.     WORD( mp + 12 ) = y + 21;
  297.     EGB_getBlock( work, mp );
  298. }
  299.  
  300. void    putcurbak( int x, int y )
  301. {
  302.     EGB_writePage( work, 0x01 );
  303.     DWORD( mp + 0 ) = (unsigned int)( mp + 14 );
  304.     WORD( mp +  4 ) = 0x014;    
  305.     WORD( mp +  6 ) = x;
  306.     WORD( mp +  8 ) = y;
  307.     WORD( mp + 10 ) = x + 18;
  308.     WORD( mp + 12 ) = y + 21;
  309.     EGB_putBlock( work, 0, mp );
  310. }
  311.  
  312.